<template>
  <div class="form_box">
    <avue-form :option="option" v-model="crudData.form" @submit="handleSubmit">
      <template #vip_first_level_distribution_rate>
        <el-input v-model="crudData.form.vip_first_level_distribution_rate"
                  placeholder="请输入开通Vip一级分销比例"
                  class="input-with-select">
          <template #prepend>
            %
          </template>
        </el-input>
      </template>
      <template #vip_second_level_distribution_rate>
        <el-input v-model="crudData.form.vip_second_level_distribution_rate"
                  placeholder="请输入开通Vip二级分销比例"
                  class="input-with-select">
          <template #prepend>
            %
          </template>
        </el-input>
      </template>
      <template #vip_third_level_distribution_rate>
        <el-input v-model="crudData.form.vip_third_level_distribution_rate"
                  placeholder="请输入开通Vip三级分销比例"
                  class="input-with-select">
          <template #prepend>
            %
          </template>
        </el-input>
      </template>
      <template #order_first_level_distribution_rate>
        <el-input v-model="crudData.form.order_first_level_distribution_rate"
                  placeholder="请输入刷单一级分销比例"
                  class="input-with-select">
          <template #prepend>
            %
          </template>
        </el-input>
      </template>
      <template #order_second_level_distribution_rate>
        <el-input v-model="crudData.form.order_second_level_distribution_rate"
                  placeholder="请输入刷单二级分销比例"
                  class="input-with-select">
          <template #prepend>
            %
          </template>
        </el-input>
      </template>
      <template #order_third_level_distribution_rate>
        <el-input v-model="crudData.form.order_third_level_distribution_rate"
                  placeholder="请输入刷单三级分销比例"
                  class="input-with-select">
          <template #prepend>
            %
          </template>
        </el-input>
      </template>
    </avue-form>
  </div>
</template>
<script setup>
import {configList, configPut} from "@/api/user/index.js";
import {ElMessage} from "element-plus";
import {onMounted} from "vue";

let props = defineProps({
  content: {
    type: Object,
    default: () => [],
    required: true
  }
})
const crudData = reactive({
  form: {},
  nowData: {},
})
const option = reactive({
  labelWidth: 200,
  size: 'medium',
  column: [
    {
      label: '开通Vip一级分销比例',
      prop: 'vip_first_level_distribution_rate',
      span: 24,
    },
    {
      label: '开通Vip二级分销比例',
      prop: 'vip_second_level_distribution_rate',
      span: 24,
    },
    {
      label: '开通Vip三级分销比例',
      prop: 'vip_third_level_distribution_rate',
      span: 24,
    },
    {
      label: '刷单一级分销比例',
      prop: 'order_first_level_distribution_rate',
      span: 24,
    },
    {
      label: '刷单二级分销比例',
      prop: 'order_second_level_distribution_rate',
      span: 24,
    },
    {
      label: '刷单三级分销比例',
      prop: 'order_third_level_distribution_rate',
      span: 24,
    },
  ]
})
const handleSubmit = (form, done) => {
  let params = {}
  params.distribution = form
  console.log('form', params)
  configPut(params).then(res => {
    ElMessage.success('操作成功')
    initData()
  }).catch(err => {
  })
  done()
}
const initData = async () => {
  await configList().then(res => {
    crudData.form = res.data.distribution
  })
}
onMounted(() => {
  initData()
})
</script>
<style scoped lang="scss">
.form_box {
  width: 100%;
  padding: 0 20px 20px 20px;
  height: calc(100vh - 120px);
  overflow-y: auto;

  ::v-deep .avue-form {
    .el-collapse-item__wrap {
      padding: 20px;
    }
  }
}
</style>
